/*
 * ER/Studio 8.0 SQL Code Generation
 * Company :      c
 * Project :      DATA MODEL
 * Author :       c
 *
 * Date Created : Monday, May 02, 2011 21:34:36
 * Target DBMS : Microsoft SQL Server 2005
 */

/* 
 * TABLE: ACTIVA_CAJA 
 */

CREATE TABLE ACTIVA_CAJA(
    id_apertura_caja    int               IDENTITY(1,1),
    nro_caja            int               NOT NULL,
    fecha_activa        datetime          NULL,
    fecha_cerrada       datetime          NULL,
    monto_inicial       numeric(17, 2)    NULL,
    monto_fin           numeric(17, 2)    NULL,
    diferencia          int               NULL,
    id_usuario          int               NOT NULL,
    estado              varchar(30)       NULL,
    CONSTRAINT PK12_1 PRIMARY KEY NONCLUSTERED (id_apertura_caja)
)
go



IF OBJECT_ID('ACTIVA_CAJA') IS NOT NULL
    PRINT '<<< CREATED TABLE ACTIVA_CAJA >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE ACTIVA_CAJA >>>'
go

/* 
 * TABLE: CAJA 
 */

CREATE TABLE CAJA(
    id_caja             int               NOT NULL,
    fecha_mov           datetime          NULL,
    total               numeric(17, 2)    NULL,
    id_apertura_caja    int               NOT NULL,
    CONSTRAINT PK3_1 PRIMARY KEY NONCLUSTERED (id_caja)
)
go



IF OBJECT_ID('CAJA') IS NOT NULL
    PRINT '<<< CREATED TABLE CAJA >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE CAJA >>>'
go

/* 
 * TABLE: DETALLE_CAJA 
 */

CREATE TABLE DETALLE_CAJA(
    id_det_cab            int               IDENTITY(1,1),
    id_caja               int               NOT NULL,
    importe_parcial       numeric(17, 2)    NULL,
    fecha                 datetime          NULL,
    importe               numeric(17, 2)    NULL,
    movimiento            varchar(30)       NULL,
    id_valor              int               NOT NULL,
    id_factura_cliente    int               NOT NULL,
    CONSTRAINT PK6_2 PRIMARY KEY NONCLUSTERED (id_det_cab, id_caja)
)
go



IF OBJECT_ID('DETALLE_CAJA') IS NOT NULL
    PRINT '<<< CREATED TABLE DETALLE_CAJA >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE DETALLE_CAJA >>>'
go

/* 
 * TABLE: TIPO_VALOR 
 */

CREATE TABLE TIPO_VALOR(
    id_valor            int             IDENTITY(1,1),
    descripcion_tipo    varchar(256)    NULL,
    descripcion         varchar(30)     NULL,
    CONSTRAINT PK7_1 PRIMARY KEY NONCLUSTERED (id_valor)
)
go



IF OBJECT_ID('TIPO_VALOR') IS NOT NULL
    PRINT '<<< CREATED TABLE TIPO_VALOR >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE TIPO_VALOR >>>'
go

/* 
 * TABLE: CAJA 
 */

ALTER TABLE CAJA ADD CONSTRAINT RefACTIVA_CAJA25 
    FOREIGN KEY (id_apertura_caja)
    REFERENCES ACTIVA_CAJA(id_apertura_caja)
go


/* 
 * TABLE: DETALLE_CAJA 
 */

ALTER TABLE DETALLE_CAJA ADD CONSTRAINT RefCAJA27 
    FOREIGN KEY (id_caja)
    REFERENCES CAJA(id_caja)
go

ALTER TABLE DETALLE_CAJA ADD CONSTRAINT RefTIPO_VALOR28 
    FOREIGN KEY (id_valor)
    REFERENCES TIPO_VALOR(id_valor)
go


